home *** CD-ROM | disk | FTP | other *** search
/ 5 Star Games: DOS Edition 2 / 5 Star Games - DOS Edition (1995)(Ready to Run).iso / dbc / db_util.c < prev    next >
C/C++ Source or Header  |  1993-12-07  |  64KB  |  2,290 lines

  1.  
  2. /****************************************************************************/
  3. /*                         DATABOSS MODULE: DB_UTIL.C                       */
  4. /*           Set the editor TAB size to 3 for correct indentation           */
  5. /****************************************************************************/
  6.  
  7. #include "db_lsc.h"
  8.  
  9. #include <conio.h>
  10. #ifndef __TURBOC__
  11.     #include <graph.h>
  12. #endif
  13. #include <io.h>
  14. #include <process.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include <time.h>
  19. #include "db_types.h"
  20. #include "db_conio.h"
  21. #include "db_crit.h"
  22. #include "db_curs.h"
  23. #include "db_date.h"
  24. #include "db_dos.h"
  25. #include "db_file.h"
  26. #include "db_funcs.h"
  27. #include "db_gvar.h"
  28. #include "db_heap.h"
  29. #include "db_key.h"
  30. #include "db_math.h"
  31. #include "db_sets.h"
  32. #include "db_str.h"
  33. #include "db_win.h"
  34. #include "db_uwin.h"
  35. #include "db_util.h"
  36.  
  37. /**********************  GLOBAL INITIALIZED VARIABLES  **********************/
  38.  
  39. byte  swc      = 31;
  40. byte  sbc      = 30;
  41. byte  hcolr    = 47;
  42. byte  hbcolr   = 46;
  43. byte  hshad    = 8;
  44. uchar hbchrs[] = "═╕│╛═╘│╒";
  45. bool  no_crlf  = False;                                              /* SN 3.5 */
  46. bool  ad_crlf  = True;                                               /* SN 3.5 */
  47.  
  48. /****************************  GLOBAL VARIABLES  ****************************/
  49.  
  50. bool         badpic,alwaysvalid,fieldchanged;
  51. int          deltas, manstate;
  52. scrproc      savescreenp;
  53. helpproc     morehelp;
  54. set          _PIC_SET;
  55. bool         _upward,_1chwait;
  56. int          pabort,fldnum;
  57. uchar        exitcode;
  58. byte         attrib;
  59. string       compstr;
  60. pathstr      datapath,filname;
  61. word         es_status;
  62. edthookproc  edthook;
  63. ewsfunctyp   ewsfunc;
  64. iesfunctyp   iesfunc;
  65. sesproctyp   sesproc;
  66. winptr       messageWindowPtr;                                     /* SN 3.5 */
  67.  
  68. /***************************  INTERNAL CONSTANTS  ***************************/
  69.  
  70. #define StartIntWin 0
  71. #define NumIntWin   4
  72.  
  73. #define Mono_Mask  0x0030
  74. #define CO80_Mask  0x0020
  75. #define CO40_Mask  0x0010
  76.  
  77. static const byte MONO_ra[] = {7,15};
  78.  
  79. #define ParmCmd "AV=  IV=  EV=  SNOW="
  80.  
  81. #define Across 65
  82. #define Down   13
  83. static uchar Selectable[Down][Across+1] = {
  84.     {"       ─           │           ║           ═           ■         "},
  85.     {"                                                                 "},
  86.     {"     ┌ ┬ ┐       ╒ ╤ ╕       ╓ ╥ ╖       ╔ ╦ ╗         ▄         "},
  87.     {"                                                                 "},
  88.     {"     ├ ┼ ┤       ╞ ╪ ╡       ╟ ╫ ╢       ╠ ╬ ╣       ▌ █ ▐       "},
  89.     {"                                                                 "},
  90.     {"     └ ┴ ┘       ╘ ╧ ╛       ╙ ╨ ╜       ╚ ╩ ╝         ▀         "},
  91.     {"                                                                 "},
  92.     {"                                                                 "},
  93.     {"                                                                 "},
  94.     {"                                                                 "},
  95.     {"                                                                 "},
  96.     {"                                                                 "}};
  97.  
  98. #define ColSz         15
  99. #define Colms         4
  100. #define Lines         13
  101. #define MinDirSpace   2048
  102. #define MaxDirEntries 512
  103. #define BSize         256
  104.  
  105. /*****************************  INTERNAL TYPES  *****************************/
  106.  
  107. typedef char        dirnamstr[ColSz + 1];
  108. typedef dirnamstr   direntries[MaxDirEntries];
  109. typedef direntries *direntptr;
  110.  
  111. /***************************  INTERNAL VARIABLES  ***************************/
  112.  
  113. static byte         lschx,lschy;
  114. static bool         nopics;
  115. static double       savetime;
  116. static winptr       intwin[NumIntWin];
  117.  
  118. static byte         attr_;
  119. static uchar        kb_char_;
  120. static bool         goodch;
  121. static bool         lastchar_,rub_flag_,exit_flag_;
  122. static int          start_,picptr_,txpos_,frac_len_,int_len_;
  123. static string       t_pic_,ts_,savefield_;
  124. static cursortyp   *cursptr_;
  125. static int          xpos_;
  126. static int          ypos_;
  127. static strptr       field_;
  128. static uchar        typ_;
  129. static strptr       pic_;
  130. static int          flen_;
  131. static byte         a_;
  132. static winptr       winp_;
  133.  
  134. static char         parml_[81],prm_[11];
  135. static pathstr      fname_;
  136.  
  137. static int          tpage_,col_,lin_,countf_,apos_;
  138. static direntptr    dirarray_;
  139. static bool         refill_;
  140.  
  141. static bool         initialized = False;
  142.  
  143. /*****************************  IMPLEMENTATION  *****************************/
  144.  
  145. strptr decnumb(string sout, string s)
  146. {
  147.     strptr scan,store;
  148.  
  149.     scan = s;
  150.     store = sout;
  151.     while (*scan && (*scan++ != *_dcpt))
  152.         *(store++) = '9';
  153.     *store = 0;
  154.     return (fstr(sout,valu(sout) - valu(s),strlen(s),strlen(scan)));
  155. }
  156.  
  157. void strsop(strptr s1, string s2, uchar op)
  158. {
  159.     int l, d;
  160.     double r1, r2;
  161.    string tempString;                                                /* SN 3.5 */
  162.    int    isFloat;                                                   /* SN 3.5 */
  163.  
  164.     l = strlen(s1);
  165.    d = strposch(*_dcpt,s1) + 1;
  166.     if (d > 0) d = l - d;                                             /* SN 3.5 */
  167.  
  168.     r1 = valu(s1);
  169.    r2 = valu(s2);
  170.     switch (op) {
  171.         case '+' : r1 += r2; break;
  172.         case '-' : r1 -= r2; break;
  173.       case '*' : r1 *= r2; break;                                    /* SN 3.5 */
  174.       case '/' : r1 /= r2; break;                                    /* SN 3.5 */
  175.    }
  176.     fstr(tempString,r1,l,d);
  177.    strcopy(s1, tempString, 0, l);                                    /* SN 3.5 */
  178. }
  179.  
  180. void writeStatusLine(strptr windowMessage)
  181. {
  182.    if (openwin(0, 1, 25, 80, 1, 79, 79, 8, "\0┐│┘─└│┌", TopCnt, ""))  {
  183.       messageWindowPtr = curwin;
  184.       writewxy(windowMessage, 0, 1, 1, messageWindowPtr);
  185.       hidewin(T_ON,messageWindowPtr);
  186.    }
  187.    return;
  188. }
  189.  
  190. void chkwrite(int outdev, string wstr, bool cr_lf)
  191. {
  192.     int bw;
  193.     string ts, ts2;
  194.     uchar ans[2];
  195.     uchar tmps1[2];
  196.  
  197.     pabort = 0;
  198.     if (cr_lf) strconcat(ts,wstr,"\r\n",NULL); else strcpy(ts,wstr);
  199.     do {
  200.         bw = write(outdev,ts,strlen(ts));
  201.         if (bw == -1) {
  202.             pabort = 1;
  203.          writeStatusLine(centre(ts2, LSC_OutputFailure, 80));
  204.          do {
  205.             *ans = upperch(getkey());
  206.          }while ((*ans != _Abort) && (*ans != _Retry));
  207.             if (*ans == _Retry) pabort = -1;
  208.          if (messageWindowPtr) closewin(&messageWindowPtr);
  209.         }
  210.         else {
  211.             pabort = 0;
  212.             if (kpressed()) {
  213.             writeStatusLine(centre(ts2, LSC_EscOrEnter, 80));
  214.             do {
  215.                *ans = getkey();
  216.             }while ((*ans != QitKey) && (*ans != Enter));
  217.             if (*ans == QitKey) pabort = 999;
  218.             else                pabort = 0;
  219.             if (messageWindowPtr) closewin(&messageWindowPtr);
  220.             }
  221.         }
  222.     } while (pabort < 0);
  223. }
  224.  
  225. void chkwriteCh(int outdev, char wch)
  226. {
  227.   int bw;
  228.   string ts2;
  229.   uchar ans[2];
  230.   uchar tmps1[2];
  231.  
  232.   pabort = 0;
  233.   do {
  234.     bw = write(outdev,&wch,1);
  235.     if (bw == -1) {
  236.       pabort = 1;
  237.       writeStatusLine(centre(ts2, LSC_OutputFailure, 80));
  238.       do {
  239.         *ans = upperch(getkey());
  240.       }while ((*ans != _Abort) && (*ans != _Retry));
  241.       if (*ans == _Retry) pabort = -1;
  242.       if (messageWindowPtr) closewin(&messageWindowPtr);
  243.     }
  244.     else {
  245.       pabort = 0;
  246.       if (kpressed()) {
  247.         writeStatusLine(centre(ts2, LSC_EscOrEnter, 80));
  248.         do {
  249.           *ans = getkey();
  250.         }while ((*ans != QitKey) && (*ans != Enter));
  251.         if (*ans == QitKey) pabort = 999;
  252.         else                pabort = 0;
  253.         if (messageWindowPtr) closewin(&messageWindowPtr);
  254.       }
  255.     }
  256.   } while (pabort < 0);
  257. }
  258.  
  259. int _calc_int(string pic)
  260. {
  261.     return (strlen(pic));
  262. }
  263.  
  264. int _calc_frac(string pic)
  265. {
  266.     return ((pic = strchr(pic,*_dcpt)) == NULL ? 0 : strlen(++pic));
  267. }
  268.  
  269. int dotPos(strptr scanString)                                                   /* SN 3.5 */
  270. {                                                                                /* SN 3.5 */
  271.    int  scanOffset;                                                              /* SN 3.5 */
  272.                                          /* SN 3.5 */
  273.    scanOffset = strlen(scanString);                                              /* SN 3.5 */
  274.    while ((scanOffset >= 0) && (*(scanString + scanOffset--) != '.')) continue;  /* SN 3.5 */
  275.    return(scanOffset);                                                           /* SN 3.5 */
  276. }                                                                                /* SN 3.5 */
  277.  
  278. void printwin(int odev, winptr winp, prtmode pmode)
  279. {
  280.     uchar wch;
  281.     int i,j,titlelen;
  282.     string tl,tln,bln,rln,lln;
  283.     largebptr lb;
  284.     wintyp twin;
  285.     uchar cstr[2],cstr1[2];
  286.  
  287.     if (winp != NULL) {
  288.         chkwrite(odev,"",True);
  289.         if ((pabort == 0) && (winp->borchrs[0] != '\0')) {
  290.             twin = *winp;
  291.             if (pmode != AllChrs) {
  292.                 for (i=0; i < 8; i++)
  293.                     twin.borchrs[i] = filterch(twin.borchrs[i],pmode);
  294.                 titlelen = strlen(twin.title);
  295.                 for (i=0; i < titlelen; i++)
  296.                     twin.title[i] = filterch(twin.title[i],pmode);
  297.             }
  298.             get4sides(&twin,tln,bln,rln,lln);
  299.             chkwrite(odev,tln,True);
  300.         }
  301.         lb = winp->winblk;
  302.         for (i=1; i <= winp->mhgt; i++) {
  303.             tl[0] = '\0';
  304.             for (j=1; j <= winp->mwid; j++) {
  305.                 wch = (*lb)[(i-1)*winp->mwid+j-1].vchar;
  306.                 if (pmode != AllChrs) wch = filterch(wch,pmode);
  307.                 strchcat(tl,wch);
  308.             }
  309.             if (winp->borchrs[0] != '\0')
  310.                 strconcat(tl,chstr(cstr,lln[i]),tl,chstr(cstr1,rln[i]),NULL);
  311.             if (pabort == 0)
  312.                 chkwrite(odev,tl,True);
  313.         }
  314.         if ((pabort == 0) && (winp->borchrs[0] != '\0'))
  315.             chkwrite(odev,bln,True);
  316.     }
  317. }
  318.  
  319. strptr expand(strptr sout, strptr instring)
  320. {
  321.     int i,x,instrlen;
  322.     string work1,work2;
  323.     char *wrk1,*rp;
  324.     bool error;
  325.  
  326.     i        = 0;
  327.     error    = False;
  328.     work2[0] = '\0';
  329.     instrlen = strlen(instring);
  330.     while ((i < instrlen) && !error) {
  331.         work1[0] = '\0';
  332.         wrk1     = work1;
  333.         if (set_member(_DIGITS,instring[i])) {
  334.             do {
  335.                 *wrk1++ = instring[i++];
  336.             } while (set_member(_DIGITS,instring[i]));
  337.             *wrk1 = '\0';
  338.  
  339.          x = ival(work1);
  340.          if (x < 1 || x > 255) error = True;
  341. /*
  342.             x = (int) strtol(work1,&rp,10);
  343.             if (*rp != '\0') error = True;
  344.             if (x > 255)     error = True;
  345. */
  346.             if (!error) {
  347.                 memset(work1,instring[i],x);
  348.                 work1[x] = '\0';
  349.                 i++;
  350.                 strcat(work2,work1);
  351.             }
  352.         }
  353.         else strchcat(work2,instring[i++]);
  354.     }
  355.     if (error) strcpy(sout,"BAD PIC");
  356.     else       trim(sout,work2);
  357.     return(sout);
  358. }
  359.  
  360. byte piclen(strptr pic, uchar typ)
  361. {
  362.     int b,tmplen;
  363.     byte fval;
  364.     string tpic;
  365.  
  366.     expand(tpic,pic);
  367.     fval = 0;
  368.     tmplen = strlen(tpic);
  369.     for (b = 0; b < tmplen; b++) {
  370.         if (set_member(_PIC_SET,tpic[b])) fval++;
  371.     }
  372.     if ((typ == _Num) && (strchr(tpic,*_dcpt) != NULL)) fval++;
  373.     return(fval);
  374. }
  375.  
  376. bool validate_fpic(strptr instr, strptr picture, uchar typ)
  377. {
  378.     int pstrlen,plen;
  379.     string tmpstr,tmpstr1,tmpstr2;
  380.  
  381.     pstrlen = strlen(instr);
  382.     plen = piclen(picture,typ);
  383.     if ((plen == 0) || (plen != pstrlen)) {
  384.         clr_line(1);
  385.         writewxy(strconcat(tmpstr,LSC_FldPicMismatch,strip(tmpstr1,istr(tmpstr1,(long) pstrlen,3)),
  386.                         LSC_PicIndicatesLen,strip(tmpstr2,istr(tmpstr2,(long) plen,3)),NULL),0x8C,1,1,NULL);
  387.         delayorkey(3.0);
  388.         clr_line(1);
  389.         if (plen < 38)
  390.             writewxy(strconcat(tmpstr,"\"",strcopy(tmpstr1,instr,0,38),"\",\"",
  391.                                 strcopy(tmpstr2,picture,0,38),"\"",NULL),0x8C,1,1,NULL);
  392.         else
  393.             writewxy(strcopy(tmpstr,instr,0,80),0x8C,1,1,NULL);
  394.         delayorkey(3.0);
  395.         clr_line(1);
  396.     }
  397.     badpic = (bool) (plen != pstrlen);
  398.     return((bool) (!badpic));
  399. }
  400.  
  401. strptr pic_fld(strptr sout, strptr field, uchar typ, byte start, byte flen, str20 pic)
  402. {
  403.     int    i, j, int_len, frac_len, tmplen;
  404.     double r_field;
  405.     string temp_fld,ws,t_pic;
  406.     char   *rp;
  407.  
  408.     ws[0] = '\0';
  409.     expand(t_pic,pic);
  410.     if (alwaysvalid || validate_fpic(field,t_pic,typ)) {
  411.         if (typ == _Num) {
  412.             frac_len = _calc_frac(t_pic);
  413.             int_len  = _calc_int(t_pic);
  414.  
  415.             r_field = valu(field);
  416.          fstr(ws, r_field, int_len, frac_len);
  417.          if (strcmp(ws, field) == 0) {
  418.                 if ((strchr(pic,Pic_Z) != NULL) && (r_field == 0.0))
  419.                     fillstr(ws,strlen(t_pic),' ');
  420.             }
  421.             else {
  422.                 audible(Beep);
  423.                 strcpy(ws,_PicErr);
  424.             }
  425.  
  426. /*
  427.             strip(temp_fld,field);
  428.             r_field = strtod(temp_fld,&rp);
  429.             if (*rp == '\0') {
  430.                 sprintf(ws,"%*.*lf",int_len,frac_len,r_field);
  431.                 if ((strchr(pic,Pic_Z) != NULL) && (r_field == 0.0))
  432.                     fillstr(ws,strlen(t_pic),' ');
  433.             }
  434.             else {
  435.                 audible(Beep);
  436.                 strcpy(ws,"ERR");
  437.             }
  438. */
  439.  
  440.         }
  441.         else {
  442.             if (nopics && empty(field)) fillstr(ws,strlen(t_pic),' ');
  443.             else {
  444.                 j = 0;
  445.                 tmplen = strlen(t_pic);
  446.                 for (i=0; i < tmplen; i++) {
  447.                     if (set_member(_PIC_SET,t_pic[i])) {
  448.                         ws[i] = field[j];
  449.                         j++;
  450.                     }
  451.                     else ws[i] = t_pic[i];
  452.                 }
  453.                 ws[i] = '\0';
  454.             }
  455.         }
  456.     }
  457.  
  458.     if (flen != 0) strcopy(sout,ws,start-1,flen);
  459.     else           strcpy(sout,ws);
  460.     return(sout);
  461. }
  462.  
  463. bool df_quickvalid(uchar typ, str20 pic)
  464. {
  465.     bool tb;
  466.     int i,tmplen;
  467.     set goodset;
  468.  
  469.     tb = True;
  470.     if (typ != _Num) {
  471.         set_union(goodset,_DIGITS,_PIC_SET);
  472.         tmplen = strlen(pic);
  473.         for(i=0; i < tmplen; i++)
  474.             if (tb) tb = set_member(goodset,pic[i]);
  475.     }
  476.     else tb = (bool)(strchr(pic,Pic_Z) == NULL);
  477.     return(tb);
  478. }
  479.  
  480. void dsp_fld(int xpos, int ypos, strptr field, uchar typ, str20 pic,
  481.                             byte start, byte flen, byte attr, winptr winp)
  482. {
  483.     string tmpstr;
  484.  
  485.     if (attr == 0) attr = attrib;
  486.    else           if (attr == 255) attr = 0;
  487.  
  488.     if (strchr(pic,Pic_B) == NULL) {
  489.         if (start < 1) start = 1;
  490.         if (df_quickvalid(typ,pic)) {
  491.             if (flen < 1) flen = (byte) strlen(field);
  492.             writewxy(strcopy(tmpstr,field,start-1,flen),attr,(byte) xpos,(byte) ypos,winp);
  493.         }
  494.         else
  495.             writewxy(pic_fld(tmpstr,field,typ,start,flen,pic),attr,(byte) xpos,(byte) ypos,winp);
  496.     }
  497.     else {
  498.         strcpy(tmpstr,"\xff\x1  ");
  499.       tmpstr[2] = (byte)strlen(field);
  500.         writewxy(tmpstr,attr,(byte) xpos,(byte) ypos,winp);
  501.     }
  502. }
  503.  
  504. void incr_flen(int incr)
  505. {
  506.     string tmpstr;
  507.  
  508.     if ((picptr_ < start_) || (picptr_ >= (start_+flen_))) {
  509.         start_ += incr;
  510.         writewxy(strcopy(tmpstr,ts_,start_-1,flen_),attr_,(byte) xpos_,(byte) ypos_,NULL);
  511.     }
  512.     else txpos_ += incr;
  513. }
  514.  
  515. void next_char(int dirn)
  516. {
  517.     int incr;
  518.     uchar cstr[2];
  519.  
  520.     if (((dirn == Left) && (picptr_ > 1)) ||
  521.          ((dirn == Right) && (picptr_ < strlen(t_pic_)))) {
  522.         incr = (dirn == Right) ? 1 : -1;
  523.         picptr_ += incr;
  524.  
  525.         if (flen_ > 0) incr_flen(incr);
  526.         else           txpos_ += incr;
  527.  
  528.         while ((!set_member(_PIC_SET,t_pic_[picptr_-1])) &&
  529.                     (((dirn == Left) && (picptr_ > 1)) ||
  530.                     ((dirn == Right) && (picptr_ < strlen(t_pic_))))) {
  531.             if (typ_ == _Num) {
  532.                 writewxy(chstr(cstr,*_dcpt),attr_,(byte) txpos_,(byte) ypos_,NULL);
  533.                 ts_[picptr_-1] = *_dcpt;
  534.             }
  535.             picptr_ += incr;
  536.             if (flen_ > 0) incr_flen(incr);
  537.             else           txpos_ += incr;
  538.         }
  539.     }
  540.     else if ((kb_char_ != EndKey) && (strlen(field_) != 1)) noise(6000,0.01);
  541.     lastchar_ = (bool) ((picptr_ == 1) || (picptr_ == strlen(ts_)));
  542.     if (!set_member(_PIC_SET,t_pic_[picptr_-1])) {
  543.         next_char((dirn+1) % 2);
  544.         lastchar_ = True;
  545.         noise(6000,0.01);
  546.     }
  547. }
  548.  
  549. void fixts(int dirn)
  550. {
  551.     int b,tpiclen;
  552.  
  553.     tpiclen = strlen(t_pic_);
  554.     if (dirn == Right) {
  555.         for (b=picptr_; b < tpiclen-1; b++)
  556.             if (!set_member(_PIC_SET,t_pic_[b])) {
  557.                 ts_[b+1] = ts_[b];
  558.                 ts_[b] = t_pic_[b];
  559.             }
  560.         if (!set_member(_PIC_SET,t_pic_[tpiclen-1])) ts_[strlen(ts_)-1] = t_pic_[tpiclen-1];
  561.     }
  562.     else {
  563.         for (b=tpiclen-1; b >= picptr_-1; b--)
  564.             if (!set_member(_PIC_SET,t_pic_[b])) {
  565.                 ts_[b-1] = ts_[b];
  566.                 ts_[b] = t_pic_[b];
  567.             }
  568.         if (!set_member(_PIC_SET,t_pic_[0])) ts_[0] = t_pic_[0];
  569.     }
  570. }
  571.  
  572. void add_char(void)
  573. {
  574.     bool negamt;
  575.     string tmpstr,tmpstr1;
  576.     int tslen;
  577.  
  578.     if (ins_flag && (typ_ != _Num)) {
  579.         tslen = strlen(ts_);
  580.         strinsert(chstr(tmpstr,kb_char_),ts_,picptr_-1);
  581.         ts_[tslen] = '\0';
  582.         fixts(Right);
  583.         next_char(Right);
  584.         if (strchr(t_pic_,Pic_B) == NULL) {
  585.             if (flen_ == 0) writewxy(ts_,attr_,(byte) xpos_,(byte) ypos_,NULL);
  586.             else            writewxy(strcopy(tmpstr,ts_,start_-1,flen_),attr_,(byte) xpos_,(byte) ypos_,NULL);
  587.         }
  588.     }
  589.     else {
  590.         if (typ_ == _Num) {
  591.             if (kb_char_ == *_dcpt) {
  592.                 if ((frac_len_ == 0) || (picptr_ > (int_len_ - frac_len_))) {
  593.                noise(1000,0.1);
  594.                goodch = False;
  595.             }
  596.                 else {
  597.                     negamt = (bool) (strchr(ts_,'-') != NULL);
  598.                     strcpy(ts_,fstr(tmpstr,valu(strcopy(tmpstr1,ts_,0,picptr_-1)),int_len_,frac_len_));
  599.                     picptr_ = int_len_ - frac_len_;
  600.                     if (negamt && (valu(ts_) == 0.0) && (picptr_ > 2)) ts_[picptr_-3] = '-';
  601.                     txpos_ = xpos_ + picptr_;
  602.                     picptr_++;
  603.                     writewxy(ts_,attr_,(byte) xpos_,(byte) ypos_,NULL);
  604.                 }
  605.             }
  606.             else {
  607.                 ts_[picptr_-1] = kb_char_;
  608.                 writewxy(chstr(tmpstr,kb_char_),attr_,(byte) txpos_,(byte) ypos_,NULL);
  609.                 next_char(Right);
  610.             }
  611.         }
  612.         else {
  613.             ts_[picptr_-1] = kb_char_;
  614.             if (t_pic_[picptr_-1] == Pic_B)
  615.                 writewxy(" ",attr_,(byte) txpos_,(byte) ypos_,NULL);
  616.             else
  617.                 writewxy(chstr(tmpstr,kb_char_),attr_,(byte) txpos_,(byte) ypos_,NULL);
  618.             next_char(Right);
  619.         }
  620.     }
  621.     gotoxy(txpos_,ypos_);
  622. }
  623.  
  624. void _editf(void)
  625. {
  626.     int i,tslen;
  627.     string tmpstr,tmpstr1;
  628.     bool specch,redisp;
  629.  
  630.     redisp     = False;
  631.     exit_flag_ = False;
  632.     exitcode   = 0;
  633.     picptr_    = 1;
  634.     txpos_     = xpos_;
  635.     while (!set_member(_PIC_SET,t_pic_[picptr_-1])) next_char(Right);
  636.  
  637.     if ((edt_spos != 0) && (edt_spos <= (byte) strlen(field_)))
  638.         for (i=1; i < edt_spos; i++) next_char(Right);
  639.  
  640.     gotoxy(txpos_,ypos_);
  641.     do {
  642.       goodch = True;
  643.         specch = False;
  644.         if (edthook != NULL) edthook(txpos_,ypos_,winp_);
  645.         kb_char_ = getkey();
  646.         if (kb_char_ == aF1) {
  647.             specch = selectchar(&kb_char_,0,0);
  648.             if (flen_ == 0) writewxy(ts_,attr_,(byte) xpos_,(byte) ypos_,NULL);
  649.             else            writewxy(strcopy(tmpstr,ts_,start_-1,flen_),attr_,(byte) xpos_,(byte) ypos_,NULL);
  650.             if (!specch) kb_char_ = ts_[picptr_];
  651.             curfun(_SetCTyp, cursptr_);
  652.         }
  653. /*************************************************************************
  654. * [DG] 09/10/92 -- Added CtrlEnter to KB_Char test, allowing CtrlEnter   *
  655. *                  to trigger exit. This is necessary because CtrlEnter  *
  656. *                  will not register as an extended key, so _XKey will   *
  657. *                  be false. Also added Tab and STab.                    *
  658. *************************************************************************/
  659.         if ((_xkey && (set_member(ExitSet,kb_char_))) || (kb_char_ == Enter)
  660.             || (kb_char_ == QitKey) || (kb_char_ == Tab) || (kb_char_ == STab)
  661.          || (kb_char_ == CtrlEnter))
  662.       {
  663. /*************************************************************************
  664. * [DG] 09/10/92 -- If CtrlEnter was pressed, remap it to F10, and set    *
  665. *                  _XKey to true, so CtrlEnter registers as F10.         *
  666. * [DG] 09/11/92 -- Mapped STab to UArr and Tab to DArr. Also, since the  *
  667. *                  remapping allows kb_char_ to get "out-of-sync" with   *
  668. *                  exitcode, so I reassigned the two.                    *
  669. *************************************************************************/
  670.         switch (kb_char_) {
  671.           case CtrlEnter : exitcode = F10;   _xkey = True; break;
  672.           case Tab       : exitcode = DArr;                break;
  673.           case STab      : exitcode = UArr;                break;
  674.           default        : exitcode = kb_char_;
  675.         }
  676.         kb_char_ = exitcode;
  677. /*****************/ /* [DG] End Modifications */ /***********************/
  678.           exit_flag_ = True;
  679.         }
  680.         else {
  681.             if ((_xkey || (kb_char_ < 32)) && !specch) {
  682.                 goodch    = False;
  683.                 lastchar_ = False;
  684.                 rub_flag_ = False;
  685.                 switch (kb_char_) {
  686.                     case BackSp :
  687.                     case LArr   :
  688.                         next_char(Left);
  689.                         if ((kb_char_ == BackSp) && (typ_ == _Ch)) {
  690.                             redisp = True;
  691.                             if (ins_flag) {
  692.                                 strconcat(tmpstr,strcopy(tmpstr,ts_,0,picptr_-1),
  693.                                                     strcopy(tmpstr1,ts_,picptr_,strlen(ts_)-picptr_)," ",NULL);
  694.                                 strcpy(ts_,tmpstr);
  695.                                 fixts(Left);
  696.                             }
  697.                             else ts_[picptr_-1] = ' ';
  698.                         }
  699.                         break;
  700.                     case CtrlLArr :
  701.                         if (!set_member(_WORDSET,ts_[picptr_-2])) {
  702.                             do {
  703.                                 next_char(Left);
  704.                             }while ((!set_member(_WORDSET,ts_[picptr_-1])) && !lastchar_);
  705.                         }
  706.                         while ((set_member(_WORDSET,ts_[picptr_-2])) && !lastchar_)
  707.                             next_char(Left);
  708.                         break;
  709.                     case RArr  :
  710.                         next_char(Right);
  711.                         break;
  712.                     case CtrlRArr :
  713.                         if (set_member(_WORDSET,ts_[picptr_-1])) {
  714.                             do {
  715.                                 next_char(Right);
  716.                             }while (set_member(_WORDSET,ts_[picptr_-2]) && !lastchar_);
  717.                         }
  718.                         while ((!set_member(_WORDSET,ts_[picptr_-1])) && !lastchar_)
  719.                             next_char(Right);
  720.                         if (lastchar_)
  721.                             while (ts_[picptr_-1] == Space) next_char(Left);
  722.                         break;
  723.                     case Del :
  724.                         redisp = True;
  725.                         strdelete(ts_,picptr_-1,1);
  726.                         if (typ_ == _Num) {
  727.                             if (picptr_ > (int_len_ - frac_len_)) strcat(ts_,"0");
  728.                             else                                  strinsert(" ",ts_,0);
  729.                         }
  730.                         else {
  731.                             strcat(ts_," ");
  732.                             fixts(Left);
  733.                         }
  734.                         break;
  735.                     case Ins :
  736.                         toggleins(cursptr_);
  737.                         break;
  738.                     case ClrKey :
  739.                         redisp = True;
  740.                         tslen = strlen(ts_);
  741.                         while (picptr_ <= tslen) {
  742.                             if (set_member(_PIC_SET,t_pic_[picptr_-1])) ts_[picptr_-1] = ' ';
  743.                             picptr_++;
  744.                         }
  745.                         picptr_ = 1;
  746.                         txpos_ = xpos_;
  747.                         start_ = 1;
  748.                         while (!set_member(_PIC_SET,t_pic_[picptr_-1])) next_char(Right);
  749.                         break;
  750.                     case Home :
  751.                         picptr_ = 1;
  752.                         txpos_ = xpos_;
  753.                         redisp = (bool) (start_ > 1);
  754.                         start_ = 1;
  755.                         while (!set_member(_PIC_SET,t_pic_[picptr_-1])) next_char(Right);
  756.                         break;
  757.                     case EndKey :
  758.                         next_char(Right);
  759.                         if (lastchar_ && (ts_[picptr_-1] == ' ')) {
  760.                             do {
  761.                                 next_char(Left);
  762.                             }while (!lastchar_ && (ts_[picptr_-1] == ' '));
  763.                             if (ts_[picptr_-1] != ' ') next_char(Right);
  764.                         }
  765.                         else {
  766.                             if (*strip(tmpstr,strcopy(tmpstr1,ts_,picptr_-1,strlen(ts_)-picptr_+1)) == '\0') {
  767.                                 do {
  768.                                     next_char(Right);
  769.                                 }while (!lastchar_);
  770.                             }
  771.                             else {
  772.                                 i = strlen(trim(tmpstr,ts_));
  773.                                 do {
  774.                                     next_char(Right);
  775.                                 }while (!lastchar_ && (picptr_ <= i));
  776.                             }
  777.                         }
  778.                         break;
  779. /*************************************************************************
  780. *  [DG] 09/10/92 -- Commented out Tab and STab so these two keys can be  *
  781. *                   used to change fields.                               *
  782. *************************************************************************/
  783. /*
  784.                     case Tab :
  785.                         for (i=1; i <= _Tab_Space; i++) next_char(Right);
  786.                         break;
  787.                     case STab :
  788.                         for (i=1; i <= _Tab_Space; i++) next_char(Left);
  789.                         break;
  790. */
  791.                 }
  792.                 if (redisp) {
  793.                     redisp = False;
  794.                     if (strchr(t_pic_,Pic_B) == NULL) {
  795.                         if (flen_ == 0) writewxy(ts_,attr_,(byte) xpos_,(byte) ypos_,NULL);
  796.                         else            writewxy(strcopy(tmpstr,ts_,start_-1,flen_),attr_,(byte) xpos_,(byte) ypos_,NULL);
  797.                     }
  798.                 }
  799.                 gotoxy(txpos_,ypos_);
  800.             }
  801.             else {
  802.                 if ((set_member(_NUMERIC,kb_char_)) && (kb_char_ != ' ') && rub_flag_) {
  803.                     fillstr(ts_,strlen(field_),' ');
  804.                     writewxy(ts_,attr_,(byte) xpos_,(byte) ypos_,NULL);
  805.                     rub_flag_ = False;
  806.                 }
  807.                 switch (t_pic_[picptr_-1]) {
  808.                     case PIC_B :
  809.                     case PIC_X :
  810.                         add_char();
  811.                         break;
  812.                     case PIC_A :
  813.                         if (set_member(_ALPHA,kb_char_)) add_char();
  814.                         else {
  815.                      goodch = False;
  816.                      noise(1000,0.1);
  817.                   }
  818.                         break;
  819.                     case PIC_Z :
  820.                     case PIC_H :
  821.                         if (set_member(_NUMERIC,kb_char_)) {
  822.                             if ((typ_ != _Ch) && (kb_char_ == ' ')) {
  823.                         noise(1000,0.1);
  824.                         goodch = False;
  825.                      }
  826.                             else add_char();
  827.                         }
  828.                         else {
  829.                      noise(1000,0.1);
  830.                      goodch = False;
  831.                   }
  832.                         break;
  833.                     case PIC_U :
  834.                         kb_char_ = upperch(kb_char_);
  835.                         add_char();
  836.                         break;
  837.                     case PIC_L :
  838.                         kb_char_ = lowerch(kb_char_);
  839.                         add_char();
  840.                         break;
  841.                     case PIC_S :
  842.                         if ((picptr_ == 1) || (set_member(_SPLITSET,ts_[picptr_-2])))
  843.                             kb_char_=upperch(kb_char_);
  844.                         add_char();
  845.                         break;
  846.  
  847.                 }
  848.             }
  849.         }
  850.     } while ((!exit_flag_) &&
  851.                 !((strlen(ts_) == 0) && (!_1chwait) && goodch));
  852.     if (edt_spos != 0) edt_spos = (byte) picptr_;
  853. }
  854.  
  855. void edt_fld(int xPos, int yPos, strptr field, uchar typ, str20 pic,
  856.                             byte flen, byte a, winptr winp)
  857. {
  858.     int        tslen;
  859.     double     r_field;
  860.     string     t_field,tmpstr;
  861.     char      *rp,*tp;
  862.     cursortyp  tcurs;
  863.  
  864.     xpos_   = xPos;
  865.     ypos_   = yPos;
  866.     field_  = field;
  867.     typ_    = typ;
  868.     pic_    = pic;
  869.     flen_   = flen;
  870.     a_      = a;
  871.     winp_   = winp;
  872.     nopics  = False;
  873.     strcpy(savefield_, field_);
  874.     attr_ = _ev;
  875.  
  876.     dsp_fld(xpos_, ypos_, field_, typ_, pic_, 0, (byte) flen_, attr_, winp_);
  877.     if (badpic) {
  878.         exitcode = QitKey;
  879.         badpic = False;
  880.     }
  881.     else {
  882.         if (winp_ != NULL) {
  883.             xpos_ += winp_->mx - 1;
  884.             ypos_ += winp_->my - 1;
  885.             cursptr_ = &winp_->curs;
  886.         }
  887.         else cursptr_ = db_malloc(sizeof(cursptr_));
  888.  
  889.         curfun(_GetCurs,&tcurs);
  890.         start_ = 1;
  891.         expand(t_pic_,pic_);
  892.         pic_fld(ts_,field_,typ_,0,0,pic_);
  893.         rub_flag_ = False;
  894.         if (start_ == 0) start_ = 1;
  895.         ins_flag = (bool) (!ins_flag);
  896.         toggleins(cursptr_);
  897.         if (typ_ == _Num) {
  898.             flen_     = 0;
  899.             rub_flag_ = True;
  900.             frac_len_ = _calc_frac(t_pic_);
  901.             int_len_  = _calc_int(t_pic_);
  902.          _editf();
  903.            if (exitcode == QitKey) strcpy(ts_,"0");
  904.          fstr(t_field, valu(ts_), int_len_, frac_len_);
  905.  
  906. /*
  907.             do {
  908.                 do {
  909.                     _editf();
  910.                     if ((exitcode == QitKey) || empty(ts_)) strcpy(ts_,"0");
  911.                     strip(t_field,ts_);
  912.                     if (t_field[0] == *_dcpt) strinsert("0",t_field,0);
  913.                     r_field = strtod(t_field,&rp);
  914.                     if (*rp != '\0') noise(1000,0.1);
  915.                 } while (*rp != '\0');
  916.  
  917.                 sprintf(t_field,"%*.*lf",int_len_,frac_len_,r_field);
  918.                 if (strlen(t_field) > strlen(t_pic_))     noise(1000,0.1);
  919.             } while (strlen(t_field) > strlen(t_pic_));
  920. */
  921.  
  922.             strcpy(field_,t_field);
  923.         }
  924.         else {
  925.             _editf();
  926.             field_[0] = '\0';
  927.             tp        = field_;
  928.             tslen     = strlen(ts_);
  929.             for (txpos_ = 0; txpos_ < tslen; txpos_++)
  930.                  if (set_member(_PIC_SET,t_pic_[txpos_])) *tp++ = ts_[txpos_];
  931.             *tp = '\0';
  932.         }
  933.         if (winp_ != curwin) {
  934.             if (strchr(t_pic_,Pic_B) == NULL) {
  935.                 if (flen_ == 0) writewxy(ts_,0,(byte) xpos_,(byte) ypos_,&winscr);
  936.                 else            writewxy(strcopy(tmpstr,ts_,0,flen_),0,(byte) xpos_,(byte) ypos_,&winscr);
  937.             }
  938.         }
  939.         if (winp_ != NULL) {
  940.             xpos_ = xpos_ - ((int) winp_->mx) + 1;
  941.             ypos_ = ypos_ - ((int) winp_->my) + 1;
  942.         }
  943.         attr_ = (a_ == 0) ? attrib : a_;
  944.         nopics = True;
  945.         dsp_fld(xpos_,ypos_,field_,typ_,pic_,0,(byte) flen_,attr_,winp_);
  946. /*************************************************************************
  947. * [DG] 09/10/92 -- Added STab to keys which trigger previous field       *
  948. *************************************************************************/
  949.         _upward = (bool) ((exitcode == UArr) || (exitcode == STab));
  950.         switch (exitcode) {
  951.             case UArr :
  952.             case STab :
  953.                 if (fldnum > 1) fldnum--;
  954.                 break;
  955.             case DArr  :
  956.             case Enter :
  957.             case Tab   :
  958.             case Nul   :
  959.                 fldnum++;
  960.                 break;
  961.         }
  962. /**********************/ /* [DG] End Modification */ /*******************/
  963.     }
  964.     curfun(_SetCTyp,&tcurs);
  965.     *cursptr_ = tcurs;
  966.     if (winp_ == NULL) db_free(cursptr_);
  967.     fieldchanged = (bool) (strcmp(savefield_,field_) != 0);
  968. }
  969.  
  970. strptr format(strptr sout, string text, string picture, int width, uchar align)
  971. {
  972.     string pict,tempstr,td;
  973.     bool leadzero,alpha,leadstar,leading,dollar,negative;
  974.     bool trimr,lsign,tsign,allsign;
  975.     int pictlen,textlen;
  976.     uchar *tp,*textp,*tdp,*pictp;
  977.  
  978.     strcpy(pict,picture); /* don't modify "picture" */
  979.     strcpy(tempstr,text); /* don't "text" */
  980.  
  981.     if (*pict == '\0') fillstr(pict,width,Pic_X);
  982.     else               expand(pict,pict);
  983.     if (*pict == '\0') chstr(pict,Pic_X);
  984.     trimr   = False;
  985.     lsign   = False;
  986.     tsign   = False;
  987.     allsign = False;
  988.  
  989.     if (pict[0] == Pic_TL) {
  990.         textp = tempstr;
  991.         while (*textp == ' ') textp++;
  992.         strcpy(tempstr,textp);
  993.         strcpy(pict,&pict[1]);
  994.     }
  995.  
  996.     tp = strchr(pict,'\0') - 1;
  997.     if (*tp == Pic_TR) {
  998.         *tp = '\0';
  999.         trimr = True;
  1000.     }
  1001.  
  1002.   alpha = False;
  1003.   for (pictlen=0; pictlen<strlen(pict); pictlen++) {
  1004.     if ((pict[pictlen] != Pic_Z) && (pict[pictlen] != Pic_H) &&
  1005.         (pict[pictlen] != Pic_Star) && (pict[pictlen] != Pic_At) &&
  1006.         (pict[pictlen] != Pic_Plus) && (pict[pictlen] != Pic_Minus) &&
  1007.         (pict[pictlen] != Pic_Dol) && (pict[pictlen] != *_dcpt)) alpha = True;
  1008.   }
  1009.     leading = True;
  1010.     td[0] = '\0';
  1011.     if (!alpha) {
  1012.         leadstar = (bool) (strchr(pict,Pic_Star) != NULL);
  1013.         leadzero = (bool) (strchr(pict,Pic_At) != NULL);
  1014.         tp = strchr(pict,Pic_Dol);
  1015.         dollar = (bool) (tp != NULL);
  1016.         if (dollar) strcpy(tp,tp+1);
  1017.         pictlen = strlen(pict);
  1018.         if ((pict[pictlen-1] == Pic_Plus) || (pict[pictlen-1] == Pic_Minus)) {
  1019.             pictlen--;
  1020.             lsign = True;
  1021.             allsign = (bool) (pict[pictlen] == Pic_Plus);
  1022.             pict[pictlen] = '\0';
  1023.  
  1024.         }
  1025.         tp = strchr(pict,'\0') - 1;
  1026.         if ((*tp == Pic_Plus) || (*tp == Pic_Minus)) {
  1027.             tsign = True;
  1028.             allsign = (bool) (*tp == Pic_Plus);
  1029.             *tp = '\0';
  1030.         }
  1031.         tp = strchr(tempstr,Pic_Minus);
  1032.         negative = (bool) (tp != NULL);
  1033.         if (negative && (tsign || lsign)) *tp = ' ';
  1034.         tp = tempstr;
  1035.         while ((*tp == ' ') && (leadzero || leadstar)) {
  1036.             if (leadstar) *tp = Pic_Star;
  1037.             else {
  1038.                 if (leadzero) *tp = '0';
  1039.             }
  1040.             tp++;
  1041.         }
  1042.         pictp = pict;
  1043.         textp = tempstr;
  1044.         tdp = td;
  1045.         textlen = strlen(tempstr);
  1046.         pictlen = strlen(pict);
  1047.         while (*pictp) {
  1048.             if ((*pictp == *_dcpt) || (*pictp == Pic_H) ||
  1049.                     (*pictp == Pic_Star) || (*pictp == Pic_At)) {
  1050.                 if (*textp) {
  1051.                     if (*textp != ' ') leading = False;
  1052.                     *tdp++ = *textp++;
  1053.                 }
  1054.                 else *tdp++ = ' ';
  1055.             }
  1056.             else if (*pictp == *_thou) {
  1057.                 if (textlen < pictlen) {
  1058.                     if (leading && !(leadzero || leadstar)) *tdp++ = ' ';
  1059.                     else                                    *tdp++ = *_thou;
  1060.                 }
  1061.             }
  1062.             pictp++;
  1063.         }
  1064.         *tdp = '\0';
  1065.         strcat(td,textp);
  1066.         if (lsign) {
  1067.             if (allsign || negative) {
  1068.                 if (negative) float_ins(Pic_Minus,td);
  1069.                 else          float_ins(Pic_Plus,td);
  1070.             }
  1071.             else strconcat(td," ",td,NULL);
  1072.         }
  1073.         else {
  1074.             tdp = strchr(td,'\0');
  1075.             if (tsign) {
  1076.                 if (allsign || negative) {
  1077.                     if (negative) *tdp++ = Pic_Minus;
  1078.                     else          *tdp++ = Pic_Plus;
  1079.                 }
  1080.                 else *tdp++ = ' ';
  1081.                 *tdp = '\0';
  1082.             }
  1083.         }
  1084.         if (dollar) float_ins(Pic_Dol,td);
  1085.     }
  1086.     else {
  1087.         if (align != _Fill) {
  1088.             pictp = pict;
  1089.             textp = tempstr;
  1090.             tdp = td;
  1091.             while (*pictp) {
  1092.             if (set_member(_PIC_SET,*pictp)) *tdp++ = (*textp) ? *textp++ : ' ';
  1093.                 else                             *tdp++ = *pictp;
  1094.                 pictp++;
  1095.             }
  1096.             *tdp = '\0';
  1097.         }
  1098.         else strcpy(td,tempstr);
  1099.     }
  1100.     strcpy(tempstr,td);
  1101.     if (trimr) trim(tempstr,tempstr);
  1102.     switch (align) {
  1103.         case CENTRE : centre(tempstr,tempstr,width);    break;
  1104.         case RIGHT  : pad(tempstr,tempstr,width,Left);     break;
  1105.         case LEFT   : pad(tempstr,tempstr,width,Right); break;
  1106.         case FILL   :
  1107.             if (width > 254) width = 254;
  1108.             fillstr(tempstr,width,tempstr[0]);
  1109.             break;
  1110.     }
  1111.     strcpy(sout,tempstr);
  1112.     return(sout);
  1113. }
  1114.  
  1115. bool validpath(void)
  1116. {
  1117.     string ts;
  1118.     fspec fr;
  1119.     bool fval;
  1120.  
  1121.     chstr(ts,'-');
  1122.     if (paramcount() >= 2) {
  1123.         strcpy(ts,paramstr(1));
  1124.         strupr(ts);
  1125.     }
  1126.     if ((ts[0] != '-') && (ts[0] != '/')) {
  1127.         strcpy(datapath,ts);
  1128.         fexpand(ts,datapath);
  1129.         fval = (bool) (ts[0] != '\0');
  1130.         if (fval) strcpy(datapath,ts);
  1131.         fsplit(datapath,fr.fdir,fr.fname,fr.fext);
  1132.     }
  1133.     else fval = True;
  1134.     return (fval);
  1135. }
  1136.  
  1137. void editdatapath(void)
  1138. {
  1139.     string ts;
  1140.     int dplast;
  1141.     str8 ts1;
  1142.  
  1143.     strchcat(strcpy(ts1,"67"),Pic_X);
  1144.     strcpy(ts,datapath);
  1145.     do {
  1146.         dbgetstr(ts,_Ch,LSC_DataFilePath,datapath,ts1,"",nocheck,nohelp);
  1147.     }while ((!path_ok(strip(ts,ts))) && (exitcode != QitKey));
  1148.     if (exitcode != QitKey) {
  1149.         fexpand(datapath,strip(ts,ts));
  1150.         dplast = strlen(datapath) - 1;
  1151.         if ((datapath[dplast] == '\\') && (dplast > 3)) datapath[dplast] = '\0';
  1152.     }
  1153. }
  1154.  
  1155. void initedit(void)
  1156. {
  1157. }
  1158.  
  1159. void parmerr(int func)
  1160. {
  1161.     byte i;
  1162.     string tmpstr;
  1163.  
  1164.     for(i=1; i <= 8; i++)
  1165.         writewxy("\xFF\x01\x50\x20",15,1,i,NULL);
  1166.     writewxy(strconcat(tmpstr,
  1167.                              "****** ",LSC_SetupFileErr," ",fname_," ******",NULL),15,1,1,NULL);
  1168.     if (func > 0)
  1169.         writewxy(strconcat(tmpstr,
  1170.                                  LSC_InvalidParam," : ",prm_,", ",LSC_AtLine," : ",NULL),15,1,2,NULL);
  1171.     else
  1172.         writewxy(strconcat(tmpstr,LSC_UnknownCmd," : ",NULL),15,1,2,NULL);
  1173.     writewxy(parml_,15,1,3,NULL);
  1174.     getkey();
  1175. }
  1176.  
  1177. int decode(string parml, string prm)
  1178. {
  1179.     uchar *equpos,*pcmd;
  1180.     int i,cmdi;
  1181.     string ts,parml1;
  1182.  
  1183.     strcpy(parml1,parml);
  1184.     equpos = strchr(parml1,'=');
  1185.     if (equpos == NULL) parmerr(0);
  1186.     strcpy(ts,equpos+1);
  1187.     strcopy(prm,ts,0,10);
  1188.     equpos[1] = '\0';
  1189.     parml1[5] = '\0';
  1190.     for (i=0; i < 5; i++)
  1191.         if (!parml1[i]) {
  1192.             parml1[i] = ' ';
  1193.             parml1[i+1] = 0;
  1194.         }
  1195.     pcmd = ParmCmd;
  1196.     for (cmdi=1; cmdi < 5; cmdi++) {
  1197.         if (strncmp(parml1,pcmd,5) == 0) break;
  1198.         pcmd += 5;
  1199.     }
  1200.     if (cmdi >= 5) {
  1201.         parmerr(0);
  1202.         cmdi = 1;
  1203.     }
  1204.     return(cmdi);
  1205. }
  1206.  
  1207. void readattr(pathstr fname)
  1208. {
  1209.     FILE *attrf;
  1210.     strptr readres;
  1211.     int parmlen;
  1212.  
  1213.     strcpy(fname_,fname);
  1214.     attrf = fopen(fname,"rt");
  1215.     if (attrf != NULL) {
  1216.         parml_[0] = '\0';
  1217.         readres = fgets(parml_,80,attrf);
  1218.         while (readres != NULL) {
  1219.             strip(parml_,parml_);
  1220.             parmlen = strlen(parml_);
  1221.             if ((*parml_) && (parml_[parmlen-1] == '\n')) parml_[parmlen-1] = '\0';
  1222.             if (*parml_) {
  1223.                 strupr(parml_);
  1224.                 switch (decode(parml_,prm_)) {
  1225.                     case 1 :
  1226.                         _av = (byte) ival(prm_);
  1227.                         if (!_av) parmerr(3);
  1228.                         break;
  1229.                     case 2 :
  1230.                         _iv = (byte) ival(prm_);
  1231.                         if (!_iv) parmerr(2);
  1232.                         break;
  1233.                     case 3 :
  1234.                         _ev = (byte) ival(prm_);
  1235.                         if (!_ev) parmerr(4);
  1236.                         break;
  1237.                     case 4 :
  1238.                         if (prm_[0] == _YES) checksnow = True;
  1239.                         else {
  1240.                             if (prm_[0] != _NO) parmerr(6);
  1241.                             else                checksnow = False;
  1242.                         }
  1243.                         break;
  1244.                 }
  1245.             }
  1246.             readres = fgets(parml_,80,attrf);
  1247.         }
  1248.         fclose(attrf);
  1249.     }
  1250. }
  1251.  
  1252. void writeattr(pathstr fname)
  1253. {
  1254.     FILE *attrfile;
  1255.     string tmpstr;
  1256.  
  1257.     attrfile = fopen(fname,"wt");
  1258.     if (attrfile != NULL) {
  1259.         fprintf(attrfile,"AV=%hu\n",_av);
  1260.         fprintf(attrfile,"IV=%hu\n",_iv);
  1261.         fprintf(attrfile,"EV=%hu\n",_ev);
  1262.         fprintf(attrfile,"SNOW=%c\n",(checksnow) ? _YES : _NO);
  1263.         fclose(attrfile);
  1264.     }
  1265.     else
  1266.         dberrm(strconcat(tmpstr,LSC_CannotCreate," ",strip(tmpstr,fname),NULL));
  1267. }
  1268.  
  1269. strptr getcline(pathstr sout, uchar typ, strptr prog, strptr cmd)
  1270. {
  1271.     string prompt,tmpstr;
  1272.     uchar *tp;
  1273.     string cmdline;      /* converted from pathstr to string - MB */
  1274.     uchar tpic[4];
  1275.  
  1276.     exitcode = ' ';
  1277.     strcpy(cmdline,cmd);
  1278.     if (typ == _Dos)
  1279.         trim(cmdline,strconcat(cmdline,prog," ",cmdline,NULL));
  1280.     if (((typ == _Dos) || (typ == _Cmd)) && !((typ == _Dos) && cmdline[0])) {
  1281.         strcpy(prompt,(typ == _Dos) ? LSC_EnterDosCmd : LSC_EnterCmdParams);
  1282.         strcpy(tpic,"78");
  1283.         strchcat(tpic,Pic_X);
  1284.         dbgetstr(cmdline,_Ch,prompt,cmdline,tpic,"",nocheck,nohelp);
  1285.     }
  1286.     if ((typ == _Dos) || (strstr(upper(tmpstr,prog),".BAT") != NULL)) {
  1287.         if ((typ == _Dos) && (*strip(tmpstr,cmdline) == '\0')) prog[0] = '\0';
  1288.         else {
  1289.             if (strstr(upper(tmpstr,prog),".BAT") != NULL) strconcat(cmdline,prog," ",cmdline,NULL);
  1290.             strconcat(cmdline,"/C ",cmdline,NULL);
  1291.             strcpy(prog,((tp = getenv("COMSPEC")) != NULL) ? tp : "") ;
  1292.         }
  1293.     }
  1294.     strcpy(sout,cmdline);
  1295.     return(sout);
  1296. }
  1297.  
  1298. void doserr(word eno, string estr)
  1299. {
  1300.     strptr e;
  1301.     string tmpstr;
  1302.  
  1303.     if (eno) {
  1304.         switch (eno) {
  1305.             case 1   : e = LSC_ExecSwapErr;  break;
  1306.             case 2   : e = DOSErr2;      break;
  1307.             case 3   : e = DOSErr3;      break;
  1308.             case 5   : e = DOSErr5;      break;
  1309.             case 6   : e = DOSErr6;      break;
  1310.             case 8   : e = DOSErr8;      break;
  1311.             case 10  : e = DOSErr10;     break;
  1312.             case 11  : e = DOSErr11;     break;
  1313.             case 15  : e = DOSErr15;     break;
  1314.             case 18  : e = DOSErr18;     break;
  1315.             case 152 : e = DOSErr152;    break;
  1316.             default  : e = LSC_UnrecognisedErr; break;
  1317.         }
  1318.         dberrm(strconcat(tmpstr,LSC_DosErrNo,istr(tmpstr,(long) eno,2)," - ",e,NULL));
  1319.     }
  1320. }
  1321.  
  1322. /* SN 3.5 created the whole function */
  1323. /* At the momemnt this routine is de-activated */
  1324.  
  1325. void db_exec(strptr aProgram, strptr cmdLine)
  1326. {
  1327. /*
  1328.    bool             tempBoolean;
  1329.    word             sfm;
  1330.    cursortyp        thisCursor;
  1331.    struct text_info textInfo;
  1332.  
  1333.    if (!(strposstr(".EXE", aProgram)) && !(strposstr(".COM", aProgram)) && (strip(aProgram, aProgram) != NULL)) es_status = 11;
  1334.    else {
  1335.       es_status = 0;
  1336.       curfun(_GetCurs, &thisCursor);
  1337.       curfun(_SetCTyp, &linecurs);
  1338.  
  1339.         swapvectors();
  1340.       tempBoolean = checksnow;
  1341.       gettextinfo(&textInfo);
  1342.       textattr(15);
  1343.  
  1344.       execlp(aProgram, cmdLine, NULL);
  1345.  
  1346.       textattr(textInfo.attribute);
  1347.       if (getvmode() != textInfo.currmode) {
  1348.          textmode(textInfo.currmode);
  1349.          checksnow = tempBoolean;
  1350.       }
  1351.  
  1352.             swapvectors();
  1353.       curfun(_SetCTyp, &thisCursor);
  1354.       _fmode = sfm;
  1355.    }
  1356.    doserr(es_status, aProgram);
  1357.     resetdeltas = True;
  1358. */
  1359.    return;
  1360. }
  1361.  
  1362. /* Re colours the window pointed to by WinP in colour passed in Attr */
  1363. /* SN 3.5                                                            */
  1364.  
  1365. void recolor(winptr winp, byte attr)
  1366. {
  1367.   winp->borcolr = attr;
  1368.   colorwin(attr, winp);
  1369.   return;
  1370. }
  1371.  
  1372. byte pickatr(byte mode, byte defaultb, byte wcol, byte hcol)
  1373. {
  1374.     uchar     rkey;
  1375.     byte      b,b1,b2,*pb;
  1376.     int       mupdn;
  1377.     uchar     s4[5];
  1378.     string    tmpstr;
  1379.     uchar     cs[2];
  1380.     winptr    iwp0, twinp, hwinp;                                     /* SN 3.5 */
  1381.  
  1382.    twinp = ColorPaletteWin();                                        /* SN 3.5 */
  1383.    if (wcol) recolor(twinp, wcol);                                   /* SN 3.5 */
  1384.    writewxy(" ", 15, (byte)18, (byte)3, twinp);                                  /* SN 3.5 */
  1385.    for (b = 1; b <= 15; b++) writewxy("█", b, (byte)(17 + b), 3, twinp);      /* SN 3.5 */
  1386.    for (b = 0; b <= 7;    b++) writewxy(" ", b, (byte)(17 + b), 3, twinp);      /* SN 3.5 */
  1387.    for (b = 1; b <= 15; b++) writewxy("■", b, (byte)(17 + b), 3, twinp);      /* SN 3.5 */
  1388.    hidewin(T_ON, twinp);                                             /* SN 3.5 */
  1389.  
  1390. /*    selectwin(intwin[0]); SN 3.5 */
  1391. /*    hidewin(T_ON,intwin[0]); SN 3.5 */
  1392. /* iwp0 = intwin[0]; Sn 3.5 */
  1393.  
  1394.     strconcat(s4,"\xFF\x01",chstr(tmpstr,(byte)(twinp->mwid-15)),"\x20",NULL);
  1395.     if (mode == 0) {
  1396.         for (b=twinp->mhgt; b >= twinp->mhgt-2; b--)
  1397.             writewxy(s4,twinp->wincolr,(byte)(twinp->mx),(byte)(twinp->my+b-1),NULL);
  1398.     }
  1399.  
  1400.     b1 = (byte) ((defaultb == 0) ? 15 : defaultb & 0x0F);
  1401.     b2 = (defaultb & 0xF0) >> 4;
  1402.     pb = &b1;
  1403.     mupdn = 0;
  1404.     do {
  1405.         if (pb == &b1) {
  1406.             writewxy(chstr(cs,24),(byte)(twinp->wincolr+0x80),(byte)(twinp->mwid-31+b1),4,twinp);
  1407.             if (mode > 0)
  1408.                 writewxy(chstr(cs,25),twinp->wincolr,(byte)(twinp->mwid-31+b2),5,twinp);
  1409.         }
  1410.         else {
  1411.             writewxy(chstr(cs,24),twinp->wincolr,(byte)(twinp->mwid-31+b1),4,twinp);
  1412.             writewxy(chstr(cs,25),(byte)(twinp->wincolr+0x80),(byte)(twinp->mwid-31+b2),5,twinp);
  1413.         }
  1414.         for (b=1; b <= 4; b++)
  1415.             attrwritewxy(13,(byte)(b1 | (b2 << 4)),(byte)(twinp->mwid-13),(byte)(b+2),twinp);
  1416.  
  1417.         writewxy(istr(tmpstr,(long) (b1 | (b2 << 4)),3),0,(byte)(twinp->mwid-5),1,twinp);
  1418.         writewxy(hexs(tmpstr,b1 | (b2 << 4),3),0,(byte)(twinp->mwid-5),8,twinp);
  1419.         rkey = getkey();
  1420.         writewxy(" ",twinp->wincolr,(byte)(twinp->mwid-31+b1),4,twinp);
  1421.         writewxy(" ",twinp->wincolr,(byte)(twinp->mwid-31+b2),5,twinp);
  1422.         if (mousekey && ((rkey == UArr) || (rkey == DArr))) {
  1423.             if ((pb == &b2) && (rkey == UArr))       mupdn++;
  1424.             else {
  1425.                 if ((pb == &b1) && (rkey == DArr)) mupdn++;
  1426.                 else                               mupdn = 0;
  1427.             }
  1428.             if (mupdn < 3) rkey = ' ';
  1429.             else           mupdn = 0;
  1430.         }
  1431.         else mupdn = 0;
  1432.  
  1433.         switch (rkey) {
  1434.             case UArr :
  1435.             case DArr :
  1436.                 if (mode > 0) pb = (pb == &b1) ? &b2 : &b1;
  1437.                 break;
  1438.             case LArr : *pb = ((byte) (*pb-1)) % 16; break;
  1439.             case RArr : *pb = (*pb+1) % 16; break;
  1440.             case HlpKey :
  1441.             hwinp = ColorPaletteHelp();                                 /* SN 3.5 */
  1442.             if (hcol) recolor(hwinp, hcol);                             /* SN 3.5 */
  1443.             disphelpwin(hwinp);                                         /* SN 3.5 */
  1444.             closewin(&hwinp);                                           /* SN 3.5 */
  1445.             break;
  1446.         }
  1447.         if ((b1 == 0) && (b1 == b2)) b1++;
  1448.     } while ((rkey != Enter) && (rkey != QitKey));
  1449.     exitcode = rkey;
  1450.    closewin(&twinp);                                                    /* SN 3.5 */
  1451.  
  1452. /*  hidewin(T_OFF,twinp); SN 3.5 */
  1453.  
  1454.     return ((rkey == QitKey) ? defaultb : (b1 | (b2 << 4)));
  1455. }
  1456.  
  1457. bool selectchar(uchar *tc, byte wcol, byte hcol)
  1458. {
  1459.     byte i,j,xp,yp;
  1460.     uchar ch;
  1461.     winptr twinp, hwinp;
  1462.     uchar cs[2];
  1463.     bool sc_result;
  1464.    uchar ts1[4];
  1465.  
  1466.     sc_result = False;
  1467.     if (openwin(0,7,3,Across,Down,31,31,8,"─┐│┘─└│┌",TopCnt,"")) {
  1468.         twinp = curwin;
  1469.         twinp->disp = True;
  1470.         dispwindow(twinp);
  1471.         for (i=1; i < 33; i++) {
  1472.             Selectable[8][i*2-1] = i;
  1473.             Selectable[9][i*2-1] = i+127;
  1474.             Selectable[10][i*2-1] = i+159;
  1475.             Selectable[11][i*2-1] = i+191;
  1476.             Selectable[12][i*2-1] = i+223;
  1477.         }
  1478.  
  1479.         Selectable[12][63] = 127;
  1480.         for (i=0; i < Down; i++) writewxy(Selectable[i],31,1,(byte)(i+1),twinp);
  1481.         xp = lschx-1;
  1482.         yp = lschy-1;
  1483.  
  1484.         do {
  1485.      writewxy(istr(ts1, Selectable[yp][xp], 3), 0,(byte)(twinp->mx),(byte)(twinp->my - 1), NULL);
  1486.             writewxy(chstr(cs,Selectable[yp][xp]),0xF0,(byte)(xp+1),(byte)(yp+1),twinp);
  1487.             ch = getkey();
  1488.             writewxy(chstr(cs,Selectable[yp][xp]),31,(byte)(xp+1),(byte)(yp+1),twinp);
  1489.             switch (ch) {
  1490.                 case HlpKey :
  1491.  
  1492.                   /*    disphelpwin(intwin[2]); SN 3.5 */
  1493.  
  1494.                hwinp = PickChHelp();                               /* SN 3.5 */
  1495.                if (hcol) recolor(hwinp, hcol);                     /* SN 3.5 */
  1496.                disphelpwin(hwinp);                                 /* SN 3.5 */
  1497.                closewin(&hwinp);                                   /* SN 3.5 */
  1498.                     break;
  1499.                 case F2 :
  1500.                 case Enter :
  1501.                 case QitKey : break;
  1502.                 case UArr :
  1503.                     if (yp > 0) {
  1504.                         j = yp;
  1505.                         do {
  1506.                             yp--;
  1507.                         }while ((Selectable[yp][xp] == ' ') && (yp > 0));
  1508.                         if (Selectable[yp][xp] == ' ') yp = j;
  1509.                     }
  1510.                     break;
  1511.                 case DArr :
  1512.                     if (yp < Down-1) {
  1513.                         j = yp;
  1514.                         do {
  1515.                             yp++;
  1516.                         }while ( (Selectable[yp][xp] == ' ') && (yp < Down-1) );
  1517.                         if (Selectable[yp][xp] == ' ') yp = j;
  1518.                     }
  1519.                     break;
  1520.                 case LArr :
  1521.                     if (xp > 0) {
  1522.                         j = xp;
  1523.                         do {
  1524.                             xp--;
  1525.                         }while ( (Selectable[yp][xp] == ' ') && (xp > 0) );
  1526.                         if (Selectable[yp][xp] == ' ') xp = j;
  1527.                     }
  1528.                     break;
  1529.                 case RArr :
  1530.                     if (xp < Across-1) {
  1531.                         j = xp;
  1532.                         do {
  1533.                             xp++;
  1534.                         }while ( (Selectable[yp][xp] == ' ') && (xp < Across-1) );
  1535.                         if (Selectable[yp][xp] == ' ') xp = j;
  1536.                 }
  1537.                 break;
  1538.             }
  1539.         } while(((ch < ' ') || (ch > '~')) && (ch != QitKey) && (ch != Enter) && (ch != F2) );
  1540.         if (ch != QitKey) {
  1541.             sc_result = True;
  1542.             lschx = xp+1;
  1543.             lschy = yp+1;
  1544.             *tc = (ch == Enter) ? Selectable[yp][xp] : ch;
  1545.         }
  1546.         else sc_result = False;
  1547.         closewin(&twinp);
  1548.     }
  1549.     return(sc_result);
  1550. }
  1551.  
  1552. void get_pat_n_nam(strptr name, extstr extn)
  1553. {
  1554.     fspec  fr;
  1555.     string ts;
  1556.     uchar *tp;
  1557.     int    slen;
  1558.  
  1559.     chstr(ts,'-');
  1560.     if (paramcount() > 1) strupr(strcpy(ts,paramstr(1)));
  1561.     if ((*ts != '-') && (*ts != '/')) {
  1562.         fexpand(fr.fpath,ts);
  1563.         if ((dotPos(fr.fpath) >= 0) && !(path_ok(fr.fpath)))
  1564.                 *(fr.fpath + dotPos(fr.fpath) + 1 ) = '\0';
  1565.         strcat(fr.fpath,extn);
  1566.         if (!exists(fr.fpath)) {
  1567.             tp = fr.fpath + strlen(fr.fpath) - strlen(extn);
  1568.             *tp = '\0';
  1569.             if (!path_ok(fr.fpath)) {
  1570.                 while ( fr.fpath[0] && (*(tp-1) != '\\')) {
  1571.           tp--;
  1572.           *tp = '\0';
  1573.         }
  1574.                 if (!path_ok(fr.fpath)) {
  1575.           getcurrentdir(fr.fpath,0);
  1576.           tp = strchr(fr.fpath,'\0');
  1577.         }
  1578.             }
  1579.             if (*(tp-1) != '\\') {
  1580.                 *tp++ = '\\';
  1581.                 *tp = '\0';
  1582.             }
  1583.         }
  1584.     }
  1585.     else {
  1586.         getcurrentdir(fr.fpath,0);
  1587.         tp = strchr(fr.fpath,'\0');
  1588.         if (*(tp-1) != '\\') {
  1589.             *tp++ = '\\';
  1590.             *tp = 0;
  1591.         }
  1592.     }
  1593.     fsplit(fr.fpath,fr.fdir,fr.fname,fr.fext);
  1594.     strcpy(datapath,fr.fdir);
  1595.     slen = strlen(datapath);
  1596.     if ((slen > 3) && (datapath[slen - 1] == '\\')) datapath[slen-1] = 0;
  1597.     strconcat(name,fr.fname,fr.fext,NULL);
  1598.     if (name[0]) strconcat(name,datapath,"\\",name,NULL);
  1599.     if ( (tp = strstr(name,"\\\\")) != NULL) strcpy(tp,tp+1);
  1600. }
  1601.  
  1602. strptr npart(pathstr sout, pathstr ps)
  1603. {
  1604.     uchar *fvp,*psp;
  1605.  
  1606.     fvp = sout;
  1607.     psp = ps;
  1608.     while (*psp) {
  1609.         if ((*psp != ' ') && (*psp != '\\')) *fvp++ = *psp;
  1610.         psp++;
  1611.     }
  1612.     *fvp = '\0';
  1613.     return(sout);
  1614. }
  1615.  
  1616. void sortdirarray(void)
  1617. {
  1618.     int i,j;
  1619.     dirnamstr ts;
  1620.     uchar *tp;
  1621.  
  1622.     for (i=0; i < countf_-1; i++) {
  1623.         tp = (*dirarray_)[i];
  1624.         for(j=i+1; j < countf_; j++)
  1625.             if (strcmp((*dirarray_)[j],tp) < 0) tp = (*dirarray_)[j];
  1626.         strcpy(ts,(*dirarray_)[i]);
  1627.         strcpy((*dirarray_)[i],tp);
  1628.         strcpy(tp,ts);
  1629.     }
  1630. }
  1631.  
  1632. void fix254s(void)
  1633. {
  1634.     int i,numf,numd,blanks;
  1635.     uchar *tp;
  1636.  
  1637.     numf = countf_;
  1638.     numd = 0;
  1639.     while ((numf > 0) && (*(tp = (*dirarray_)[numf-1]) == 254)) {
  1640.         if (strstr(tp,"..\\") != NULL) pad(tp,LSC_ParentDir,ColSz-1,Right);
  1641.         else                           pad(tp,strcat(strcpy(tp,strip(tp,tp)+1),"\\"),ColSz-1,Right);
  1642.         numf--;
  1643.         numd++;
  1644.     }
  1645.     if ((numd > 0) && (numd != countf_)) {
  1646.         blanks = Colms - (numf % Colms);
  1647.         if (blanks < Colms) blanks += Colms;
  1648.         for (i=blanks+numd-1; i >= 0; i--) {
  1649.             if (i >= blanks) strcpy((*dirarray_)[countf_+i-numd],(*dirarray_)[countf_+i-(blanks+numd)]);
  1650.             else             pad((*dirarray_)[countf_+i-numd],"",ColSz-1,Right);
  1651.         }
  1652.         countf_ += blanks;
  1653.     }
  1654. }
  1655.  
  1656. void step(int s)
  1657. {
  1658.     string tmpstr;
  1659.  
  1660.     do {
  1661.         if ((apos_+s) >= countf_) s = countf_-apos_-1;
  1662.         else {
  1663.             if ((apos_+s) < 0)     s = -apos_;
  1664.         }
  1665.  
  1666.         apos_ += s;
  1667.         col_ += s;
  1668.         if (col_ > Colms) {
  1669.             col_ %= Colms;
  1670.             if (col_ == 0) col_ = Colms;
  1671.             lin_++;
  1672.             if (lin_ > Lines) {
  1673.                 lin_--;
  1674.                 tpage_ += Colms;
  1675.                 refill_ = True;
  1676.             }
  1677.         }
  1678.         else {
  1679.             if (col_ <= 0) {
  1680.                 col_ = (col_ % Colms)+Colms;
  1681.                 if (col_ == 0) col_ = Colms;
  1682.                 lin_--;
  1683.                 if (lin_ <= 0) {
  1684.                     lin_++;
  1685.                     tpage_ -= Colms;
  1686.                     refill_ = True;
  1687.                 }
  1688.             }
  1689.         }
  1690.     } while (*strip(tmpstr,(*dirarray_)[apos_]) == 0);
  1691. }
  1692.  
  1693. strptr dirpick(strptr sout, pathstr mask, word include, word exclude, byte wcol, byte hcol)
  1694. {
  1695.     int        fatr,err,maxstore,x,y;
  1696.     uchar      ukey;
  1697.     word       allocated;
  1698.     pathstr    dirpart,savd,savp,mask_,tmask1,tmask2;
  1699.     dirnamstr  search,savsch,fname,dsppic;
  1700.     findrec    srchrec;
  1701.     winptr     twinp, hwinp;
  1702.     bool       newdir;
  1703.     uchar     *tp,*dap;
  1704.     string     ts,ts1;
  1705.     int        tlen;
  1706.     bool       posresult,findok;
  1707.    byte       saveswc, savesbc;
  1708.  
  1709.  
  1710.    saveswc = swc;
  1711.    savesbc = sbc;
  1712.  
  1713.     strcpy(mask_,mask);
  1714.     *sout = '\0';
  1715.     x = strlen(mask_) - 1;
  1716.     while ((x >= 0) && (mask_[x] != ':') && (mask_[x] != '\\')) x--;
  1717.     strcpy(tmask1,&mask_[x+1]);
  1718.  
  1719.     x = (scrwid-(Colms*ColSz+2))/2;
  1720.     if ((allocavail((MinDirSpace + (Colms * ((ColSz * Lines) + 2))))) == (MinDirSpace + (Colms * ((ColSz * Lines) + 2)))) {
  1721.       if (wcol) {
  1722.          swc = wcol;
  1723.          sbc = wcol;
  1724.       }
  1725.         if    (openwin(0,x,5,Colms*ColSz,Lines+2,swc,sbc,8,"─┐│┘─└│┌",TopCnt,tmask1)) {
  1726.            twinp = curwin;
  1727.            twinp->disp = True;
  1728.            dispwindow(twinp);
  1729.            writewxy(centre(ts,LSC_ChangeDrives,twinp->mwid),0,1,twinp->mhgt,twinp);
  1730.            allocated = allocavail(MaxDirEntries*sizeof(dirnamstr));
  1731.            maxstore = allocated/sizeof(dirnamstr);
  1732.            dirarray_ = db_malloc(maxstore*sizeof(dirnamstr));
  1733.            dirpart[0] = '\0';
  1734.            x = strlen(mask_)-1;
  1735.            while ((mask_[x] != '\\') && (mask_[x] != ':') && (x >= 0)) x--;
  1736.            if (x >= 0) {
  1737.                strcopy(dirpart,mask_,0,x+1);
  1738.                strcpy(mask_,&mask_[x+1]);
  1739.            }
  1740.            if ((dirpart[0] == '\0') || !path_ok(dirpart)) getcurrentdir(dirpart,0);
  1741.            tp = strchr(dirpart,'\0');
  1742.            if (*(tp-1) != '\\') {
  1743.                *tp++ = '\\';
  1744.                *tp = '\0';
  1745.            }
  1746.            do {
  1747.                countf_ = 0;
  1748.                writewxy(centre(ts,LSC_Searching,twinp->mwid),(byte)(diratr | 0x80),1,(byte)(twinp->mhgt-1),twinp);
  1749.                  strip(tmask1,mask_);
  1750.                if((tp = strchr(tmask1,',')) != NULL) {
  1751.                      *tp = '\0';
  1752.                    strcpy(tmask2,tmask1);
  1753.                    strcpy(tmask1,tp+1);
  1754.                }
  1755.                else {
  1756.                    strcpy(tmask2,tmask1);
  1757.                    tmask1[0] = '\0';
  1758.                }
  1759.                fatr = include & (0xFF ^ A_DIREC);
  1760.                findok = db_findfirst(strconcat(ts,dirpart,tmask2,NULL),&srchrec,fatr);
  1761.                do {
  1762.                      if (findok && ((srchrec.attrib & exclude) == 0) &&
  1763.                         (((srchrec.attrib & fatr) != 0) || (srchrec.attrib == 0))) {
  1764.                        countf_++;
  1765.                        pad((*dirarray_)[countf_-1],srchrec.name,ColSz-1,Right);
  1766.                    }
  1767.                    findok = db_findnext(&srchrec);
  1768.                    while (!findok && *tmask1) {
  1769.                          if ((tp = strchr(tmask1,',')) != NULL) {
  1770.                              *tp = '\0';
  1771.                              strcpy(tmask2,tmask1);
  1772.                            strcpy(tmask1,tp+1);
  1773.                          }
  1774.                        else {
  1775.                             strcpy(tmask2,tmask1);
  1776.                              tmask1[0] = '\0';
  1777.                        }
  1778.                        findok = db_findfirst(strconcat(ts,dirpart,tmask2,NULL),&srchrec,fatr);
  1779.                    }
  1780.                } while (findok && ((countf_+(2*Colms)) < maxstore));
  1781.                if (!findok && ((exclude & A_DIREC) == 0)) {
  1782.                    fatr = A_DIREC;
  1783.                     findok = db_findfirst(strconcat(ts,dirpart,"*.*",NULL),&srchrec,fatr);
  1784.                      do {
  1785.                        if (findok && ((srchrec.attrib & fatr) != 0) &&(strcmp(srchrec.name,".") != 0) &&
  1786.                                 (strcmp(srchrec.name,"..") != 0)) {
  1787.                              countf_++;
  1788.                              tp = (*dirarray_)[countf_-1];
  1789.                            pad(tp,strconcat(tp,"\xFE",srchrec.name,NULL),ColSz-1,Right);
  1790.                          }
  1791.                          findok = db_findnext(&srchrec);
  1792.                    } while (findok && ((countf_+(2*Colms)) < maxstore));
  1793.                }
  1794.                if ((strlen(dirpart) > 3) && ((exclude & A_DIREC) == 0)) {
  1795.                    countf_++;
  1796.                    pad((*dirarray_)[countf_-1],"\xFE\xFE..\\",ColSz-1,Right);
  1797.                  }
  1798.                  sortdirarray();
  1799.                  fix254s();
  1800.                  search[0] = '\0';
  1801.                  strconcat(dsppic,"12",chstr(ts,Pic_U),NULL);
  1802.                refill_ = True;
  1803.                tpage_ = 0;
  1804.                col_ = 1;
  1805.                lin_ = 1;
  1806.                apos_ = 0;
  1807.                do {
  1808.                    newdir = False;
  1809.                    if (refill_) {
  1810.                     writewxy(centre(ts,dirpart,twinp->mwid),diratr,1,(byte)(twinp->mhgt-1),twinp);
  1811.                         for (y=1; y <= Lines; y++) {
  1812.                             for (x=1; x <= Colms; x++) {
  1813.                                 err = (y-1)*Colms+x+tpage_;
  1814.                                 if (err <= countf_)
  1815.                                     strcpy(fname,(*dirarray_)[err-1]);
  1816.                                 else
  1817.                                     strconcat(fname,"\xFF\x01",chstr(ts,ColSz-1)," ",NULL);
  1818.                                 writewxy(fname,0,(byte) ((x-1)*ColSz+2),(byte) y,twinp);
  1819.                             }
  1820.                         }
  1821.                         refill_ = False;
  1822.                     }
  1823.                     x = twinp->wid - 2 - strlen(search);
  1824.                     strconcat(ts,search,"\xFF\x01",chstr(ts,(uchar) x),
  1825.                                      chstr(ts1,twinp->borchrs[4]),NULL);
  1826.                 writewxy(ts,0,(byte)(twinp->x+1),(byte)(twinp->y+twinp->hgt),NULL);
  1827.                     hilite((byte) ((col_-1)*ColSz+2),(byte) lin_,ColSz-1,diratr,0,twinp);
  1828.                     ukey = getkey();
  1829.                     if ((ukey >= 'a') && (ukey <= 'z'))
  1830.                         ukey -= 'a'-'A';
  1831.                     strcpy(savsch,search);
  1832.                     search[0] = '\0';
  1833.                     if (_ckey && (ukey >= CtrlA) && (ukey <= CtrlZ)) {
  1834.                         if (ukey != dirpart[0]) {
  1835.                             strcpy(savp,dirpart);
  1836.                             getcurrentdir(savd,0);
  1837.                             getcurrentdir(dirpart,ukey);
  1838.                             if (!changedir(dirpart)) {
  1839.                                  doserr(_doserrno,dirpart);
  1840.                                  strcpy(dirpart,savp);
  1841.                                ukey = ' ';
  1842.                            }
  1843.                            else {
  1844.                                tp = strchr(dirpart,'\0');
  1845.                                if (*(tp-1) != '\\') {
  1846.                                    *tp++ = '\\';
  1847.                                    *tp = '\0';
  1848.                                }
  1849.                                newdir = True;
  1850.                            }
  1851.                            changedir(savd);
  1852.                          }
  1853.                      }
  1854.                 else if (countf_ > 0) {
  1855.  
  1856. /*             else {*/
  1857.                          switch(ukey) {
  1858.                              case HlpKey :
  1859.                       /*  disphelpwin(intwin[3]); SN 3.5 */
  1860.                         hwinp = DirPickHelp();
  1861.                         if (hcol) recolor(hwinp, hcol);
  1862.                         disphelpwin(hwinp);
  1863.                         closewin(&hwinp);
  1864.                         break;
  1865.                              case Enter  :
  1866.                                  dap = (*dirarray_)[apos_];
  1867.                                  if (empty(dap))
  1868.                                      ukey = ' ';
  1869.                                  else {
  1870.                                      tp = LSC_ParentDir;
  1871.                                      tlen = strlen(tp);
  1872.                                      posresult = (bool) (strncmp(tp,dap,tlen) == 0);
  1873.                                      if (posresult || (strchr(dap,'\\') != NULL)) {
  1874.                                          if (posresult)
  1875.                                              fexpand(dirpart,strcat(dirpart,"..\\"));
  1876.                                          else
  1877.                                             fexpand(dirpart,strcat(dirpart,strip(ts,dap)));
  1878.                                         if (dirpart[4] == '\0')
  1879.                                             dirpart[3] = '\0';
  1880.                                         newdir = True;
  1881.                                    }
  1882.                                }
  1883.                                  break;
  1884.                              case LArr   : step(-1); break;
  1885.                              case RArr   : step(1);  break;
  1886.                              case UArr   : step(-4); break;
  1887.                              case DArr   : step(4);  break;
  1888.                            case PgUp   :
  1889.                                 y = (lin_ > 1) ? lin_-1 : Lines;
  1890.                                  for (x=1; x <= y; x++) step(-4);
  1891.                                 break;
  1892.                              case PgDn   :
  1893.                                y = (lin_ < Lines) ? Lines-lin_ : Lines;
  1894.                                 for (x=1; x <= y; x++) step(4);
  1895.                                break;
  1896.                            case Home   :
  1897.                                 refill_ = (bool) (tpage_ > 0);
  1898.                                 apos_ = 0;
  1899.                                  tpage_ = 0;
  1900.                                col_ = 1;
  1901.                                lin_ = 1;
  1902.                                break;
  1903.                              case EndKey :
  1904.                                  apos_ = countf_-1;
  1905.                                  refill_ = True;
  1906.                                col_ = (apos_+1) % Colms;
  1907.                                 if (col_ == 0) col_ = Colms;
  1908.                                  lin_ = countf_ / Colms;
  1909.                                 if (countf_ % Colms) lin_++;
  1910.                                  if (lin_ > Lines) {
  1911.                                    tpage_ = (lin_-Lines) * Colms;
  1912.                                     lin_ = Lines;
  1913.                                }
  1914.                                break;
  1915.                            default :
  1916.                                strcpy(search,savsch);
  1917.                                 if ((ukey == BackSp) && (search[0] != '\0'))
  1918.                                     search[strlen(search)-1] = '\0';
  1919.                                 else {
  1920.                                      if ((ukey != BackSp) && (strlen(search) < ColSz))
  1921.                                          strchcat(search,ukey);
  1922.                                  }
  1923.                                 if (search[0] != '\0') {
  1924.                                     while ((apos_ < countf_-1) && (strcmp(search,npart(ts,(*dirarray_)[apos_])) > 0) &&
  1925.                                              (strncmp(search,(*dirarray_)[apos_],strlen(search)) != 0))
  1926.                                          step(1);
  1927.                                    while ((apos_ > 0) &&
  1928.                                              (strcmp(search,npart(ts,(*dirarray_)[apos_])) < 0) &&
  1929.                                                   (strncmp(search,(*dirarray_)[apos_-1],strlen(search)) == 0))
  1930.                                        step(-1);
  1931.                                 }
  1932.                                  break;
  1933.                        }
  1934.                     }
  1935.                  } while (!newdir && (_ckey || ((ukey != QitKey) && (ukey != Enter))));
  1936.            } while ((ukey != QitKey) && (_ckey || newdir));
  1937.            closewin(&twinp);
  1938.            if ((ukey == Enter) && (countf_ > 0)) {
  1939.  
  1940. /*   if (ukey == Enter) {*/
  1941.                strconcat(sout,dirpart,strip(ts,(*dirarray_)[apos_]),NULL);
  1942.                strcpy(datapath,dirpart);
  1943.                if ((tlen = strlen(datapath)) != 0) datapath[tlen-1] = '\0';
  1944.              }
  1945.            db_free(dirarray_);
  1946.        }
  1947.    }
  1948.     return (sout);
  1949. }
  1950.  
  1951. void disphelpwin(winptr winp)
  1952. {
  1953.     uchar resp;
  1954.     winptr twinp;
  1955.     byte tlen;
  1956.     uchar *tp;
  1957.  
  1958.     if (winp != NULL) {
  1959.         twinp = winp;
  1960.         selectwin(twinp);
  1961.     }
  1962.     else {
  1963.         tp = LSC_NoHelp;
  1964.         tlen = (byte) strlen(tp);
  1965.         if (openwin(0,(byte)((80-tlen)/2),12,(byte)(tlen+2),1,hcolr,hbcolr,hshad,hbchrs,TopCnt,"")) {
  1966.             twinp = curwin;
  1967.             writewxy(tp,0,2,1,twinp);
  1968.         }
  1969.     }
  1970.     if (twinp != NULL) {
  1971.         do {
  1972.             hidewin(T_ON,twinp);
  1973.             tp = LSC_ManualAvail;
  1974.             if (((manstate == _located) || (manstate == _opened)) &&
  1975.                     (strlen(tp) < (twinp->mwid-2)) && (twinp->borchrs[0] != '\0'))
  1976.                 writewxy(tp,0,(byte)(twinp->mx+1),(byte)(twinp->my+twinp->mhgt),NULL);
  1977.             resp = getkey();
  1978.             hidewin(T_OFF,twinp);
  1979.             if ((resp == HlpKey) && (morehelp != NULL)) morehelp();
  1980.         } while ((resp == HlpKey) && (winp != NULL));
  1981.         if (winp == NULL) closewin(&twinp);
  1982.     }
  1983. }
  1984.  
  1985. void disphelp(winptr hwin)
  1986. {
  1987.     byte y;
  1988.     winptr twinp;
  1989.     string ts;
  1990.  
  1991.     y = (wherey() < (scrhgt - 3)) ? scrhgt - 1 : 2;
  1992.     strconcat(ts," ",LSC_EditMenu," ",NULL);
  1993.     if (openwin(0,2,y,78,1,63,63,8,"─┐│┘─└│┌",TopCnt,ts)) {
  1994.         twinp = curwin;
  1995.         writewxy(centre(ts,LSC_MemoEditMenu,78),63,1,1,twinp);
  1996.         hidewin(T_ON,twinp);
  1997.     }
  1998.     else twinp = NULL;
  1999.     disphelpwin(hwin);
  2000.     if (twinp != NULL) closewin(&twinp);
  2001. }
  2002.  
  2003. void dspmsge(string prompt, string msge, double respond)
  2004. {
  2005.     byte y;
  2006.     winptr twinp;
  2007.     string ts;
  2008.  
  2009.     y = (byte) ((wherey() <= (scrhgt-5)) ? wherey() : 1);
  2010.     if (prompt[0])
  2011.         strconcat(ts," ",prompt," ",NULL);
  2012.     else
  2013.         ts[0] = '\0';
  2014.     if (openwin(0,2,y+2,78,1,79,79,8,"─┐│┘─└│┌",TopCnt,ts)) {
  2015.         twinp = curwin;
  2016.         twinp->disp = True;
  2017.         dispwindow(twinp);
  2018.         writewxy(centre(ts,msge,78),79,1,1,twinp);
  2019.         if (respond > 0.01)    delayorkey(respond);
  2020.       else                   while(!kpressed());
  2021.         closewin(&twinp);
  2022.     }
  2023.     else {
  2024.         gotoxy(2,25);
  2025.         cwrite(centre(ts,msge,78));
  2026.     }
  2027. }
  2028.  
  2029. void dberrm(string erm)
  2030. {
  2031.     audible(Error);
  2032.     dspmsge("",erm,0.0);
  2033.     getkey();
  2034. }
  2035.  
  2036. strptr dbgetstr(string sout, uchar typ, str80 prompt, string defaultstr,
  2037.                                 str20 pic, str80 ermsg, chkfunc check, helpproc help)
  2038. {
  2039.     byte len,tlen,cx,cy;
  2040.     int ml;
  2041.     bool tb;
  2042.     string ts,tpic,tprompt;
  2043.     cursortyp tcurs;
  2044.     winptr twinp;
  2045.  
  2046.     strcpy(tprompt,prompt);
  2047.     if (strlen(tprompt) > 70) tprompt[70] = '\0';
  2048.     strconcat(tprompt," ",tprompt," : ",NULL);
  2049.     len = piclen(pic,typ); if (len==0) len = strlen(defaultstr);
  2050.     ml = len + strlen(tprompt);
  2051.     if (ml <= 78) {
  2052.         tlen = max(len,strlen(pic));
  2053.         cx = (byte) fround((scrwid-ml)/2.0) + 1;
  2054.     }
  2055.     else {
  2056.         ml = 78;
  2057.         tlen = (byte) (ml-strlen(tprompt));
  2058.         cx = 2;
  2059.     }
  2060.     strcpy(tpic,pic);
  2061.     if (tpic[0] == '\0') strchcat(strip(tpic,istr(tpic,(long) len,3)),Pic_X);
  2062.     if (typ == _Num)     fstr(ts,valu(defaultstr),len,_calc_frac(tpic));
  2063.     else                 strcopy(ts,pad(ts,defaultstr,len,Right),0,len);
  2064.     curfun(_GetCurs,&tcurs);
  2065.     cy = (tcurs.crow >= (scrhgt-2)) ? tcurs.crow-2 : tcurs.crow+2;
  2066.     if (openwin(0,cx,cy,(byte) ml,1,_iv,_av,8,"─┐│┘─└│┌",TopCnt,"")) {
  2067.         twinp = curwin;
  2068.         writewxy(tprompt,0,1,1,twinp);
  2069.         twinp->disp = True;
  2070.         dispwindow(twinp);
  2071.         do {
  2072.             tb = True;
  2073.             edt_fld(strlen(tprompt)+1,1,ts,typ,tpic,tlen,_av,twinp);
  2074.             if ((exitcode != QitKey) && (exitcode != HlpKey)) {
  2075.                 tb = check(ts);
  2076.                 strcopy(ts,pad(ts,ts,len,Right),0,len);
  2077.                 dsp_fld(strlen(tprompt)+1,1,ts,typ,tpic,0,tlen,_av,twinp);
  2078.             }
  2079.             if (exitcode == HlpKey) help();
  2080.             else {
  2081.                 if ((ermsg[0]) && !tb && (exitcode != QitKey)) dberrm(ermsg);
  2082.             }
  2083. /*************************************************************************
  2084. * [DG] 09/10/92 -- Added CtrlEnter to exitcode test.                     *
  2085. *************************************************************************/
  2086.         } while ((!tb || ((exitcode != Enter)  && (exitcode != XeptKey)))
  2087.                           &&  (exitcode != QitKey) && (exitcode != CtrlEnter));
  2088.         closewin(&twinp);
  2089.     }
  2090.     curfun(_SetCPos,&tcurs);
  2091.     curfun(_SetCTyp,&tcurs);
  2092.     if (exitcode == QitKey) pad(ts,defaultstr,len,Right);
  2093.     strcpy(sout,ts);
  2094.     return(sout);
  2095. }
  2096.  
  2097. void updexe(strptr idstr, word len)
  2098. {
  2099.     word b,j,nr;
  2100.     long fpos;
  2101.     uchar buf[BSize];
  2102.     FILE *exef;
  2103.     int idstrlen;
  2104.  
  2105.     idstrlen = strlen(idstr);
  2106.     if ((idstrlen > 1) && (_osmajor >= 3)) {
  2107.         exef = fopen(thisprog.fpath,"r+b");
  2108.         fpos = filelength(fileno(exef))-BSize;
  2109.         if (fpos < 0) fpos = 0;
  2110.         do {
  2111.             j = 0;
  2112.             b = 0;
  2113.             fseek(exef,fpos,SEEK_SET);
  2114.             nr = fread(buf,1,BSize,exef);
  2115.             while ((j < idstrlen) && (b < nr)) {
  2116.                 if (buf[b] == idstr[j]) j++;
  2117.                 else                    j = 0;
  2118.                 b++;
  2119.             }
  2120.             if (j == idstrlen) {
  2121.                 fseek(exef,fpos+b-idstrlen,SEEK_SET);
  2122.                 fwrite(idstr,1,len,exef);
  2123.             }
  2124.             else {
  2125.                 fpos = fpos-BSize+idstrlen+2;
  2126.                 if (fpos < 0) fpos = 0;
  2127.             }
  2128.         } while ((j != idstrlen) && (fpos != 0));
  2129.         fclose(exef);
  2130.     }
  2131. }
  2132.  
  2133. bool chkds(string instr)
  2134. {
  2135.     return((bool) ((ival(instr) == 0) || (ival(instr) >= 5) && (ival(instr) <= MaxSecs)));
  2136. }
  2137.  
  2138. void setdeltas(void) {
  2139.     string ts;
  2140.     char ts1[4],ts2[3];
  2141.  
  2142.     ts2[0] = '3';
  2143.     ts2[1] = Pic_H;
  2144.     ts2[2] = '\0';
  2145.     dbgetstr(ts,_Num,LSC_ScreenSaveDelay,istr(ts1,(long) deltas,3),ts2,"",chkds,nohelp);
  2146.     if (exitcode != QitKey) deltas = (int) ival(ts);
  2147. }
  2148.  
  2149. void savedmessage(void)
  2150. {
  2151.     int w,x,y;
  2152.     winptr twinp;
  2153.     str80 tm;
  2154.     int tlen;
  2155.     string ts;
  2156.  
  2157. /*  SN 3.5
  2158.    x = 0;
  2159.     for (w=1; w <= 3; w++)
  2160.         if ((tlen = strlen((*db_util_langp)[12+w])) > x)
  2161.             x = tlen;
  2162. */
  2163.  
  2164.    x = maximum(11, strlen(LSC_ScreenSaveActive));
  2165.    x = maximum(x, strlen(LSC_PressAnyKey));
  2166.     if (openwin(0,2,2,(byte) (x+2),3,swc,sbc,0,"─┐│┘─└│┌",TopCnt,"")) {
  2167.         bg_on = False;
  2168.         twinp = curwin;
  2169.         writewxy(centre(ts,LSC_ScreenSaveActive,twinp->mwid),0,1,2,twinp);
  2170.         writewxy(centre(ts,LSC_PressAnyKey,twinp->mwid),0,1,3,twinp);
  2171.         twinp->disp = True;
  2172.         dispwindow(twinp);
  2173.         srand((word) (time(NULL) % 37));
  2174.         do {
  2175.             x = (rand() % (scrwid-twinp->mwid-3))+2;
  2176.             y = (rand() % (scrhgt-twinp->mhgt-3))+2;
  2177.             w = x-twinp->mx;
  2178.             for (x=1; x <= abs(w); x++) {
  2179.                 scrollwin((byte) ((w > 0) ? _Right_ : _Left_),twinp);
  2180.                 delay(5);
  2181.             }
  2182.             w = y-twinp->my;
  2183.             for (x=1; x <= abs(w); x++) {
  2184.                 scrollwin((byte) ((w > 0) ? _Down_ : _Up_),twinp);
  2185.                 delay(20);
  2186.             }
  2187.             for (w=1; w <= 50; w++)
  2188.                 if (!kpressed()) {
  2189.                     centre(tm,get_time(ts,_Full),twinp->mwid);
  2190.                     writewxy(tm,0,1,1,twinp);
  2191.                     delay(100);
  2192.                 }
  2193.         } while (!kpressed());
  2194.         bg_on = True;
  2195.         closewin(&twinp);
  2196.     }
  2197. }
  2198.  
  2199. void screensave(void)
  2200. {
  2201.     word      bs;
  2202.     double    tm;
  2203.     cursortyp tcurs;
  2204.     ptr       savbuf;
  2205.  
  2206.     if ((&savescreenp != NULL) && (deltas >= 1)) {
  2207.         if (resetdeltas) {
  2208.             resetdeltas = False;
  2209.             savetime = realtime();
  2210.         }
  2211.         else {
  2212.             tm = realtime();
  2213.             if (abs((int) (tm-savetime)) > deltas) {
  2214.                 bs = scrhgt * scrwid * 2;
  2215.                 if (allocavail(bs) == bs) {
  2216.                     curfun(_GetCurs,&tcurs);
  2217.                     savbuf = db_malloc(bs);
  2218.                     memmove(savbuf,actvid,bs);
  2219.                     clrscr();
  2220.                     savescreenp();
  2221.                     resetdeltas = True;
  2222.                     getkey();
  2223.                     clrscr();
  2224.                     memmove(actvid,savbuf,bs);
  2225.                     db_free(savbuf);
  2226.                     curfun(_SetCPos,&tcurs);
  2227.                     curfun(_SetCTyp,&tcurs);
  2228.                 }
  2229.             }
  2230.         }
  2231.     }
  2232. }
  2233.  
  2234. void readinternal(pathstr fnam, int s, int n, ptr iw)
  2235. {
  2236.     pathstr wfnam;
  2237.     string ts;
  2238.  
  2239.     fsearch(wfnam,fnam,strconcat(ts,lookalong,";",datapath,NULL));
  2240.     if (wfnam[0]) readintwin(wfnam,s,n,iw);
  2241.     else {
  2242.         strconcat(ts,"\"",fnam,"\" ",DOSErr2,"\r\n",NULL);
  2243.         cwrite(ts);
  2244.         exit(0);
  2245.     }
  2246. }
  2247.  
  2248. /**********************  UNIT INITIALIZATION/EXIT CODE  *********************/
  2249.  
  2250. void db_util_init(void)
  2251. {
  2252.     string ts;
  2253.  
  2254.     if (!initialized) {
  2255.         initialized = True;
  2256.         db_crit_init();
  2257.         db_funcs_init();
  2258.         db_gvar_init();
  2259.         db_heap_init();
  2260.         db_curs_init();
  2261.         db_key_init();
  2262.         db_date_init();
  2263.         db_win_init();
  2264.         edthook = NULL;
  2265.         clrscr();
  2266.         gotoxy(1,10);
  2267.         manstate = _closed;
  2268.         nopics = True;
  2269.         badpic = False;
  2270.         alwaysvalid = True;
  2271.         deltas = 150;
  2272.         resetdeltas = True;
  2273.         savescreenp = savedmessage;
  2274.         ssave = screensave;
  2275.         morehelp = NULL;
  2276.         ewsfunc = NULL;
  2277.         iesfunc = NULL;
  2278.         sesproc = NULL;
  2279.         readattr(AttrFName);
  2280.         attrib = _av;
  2281.         _1chwait = False;
  2282.         getcurrentdir(datapath,0);
  2283.         set_make(_PIC_SET,Pic_X,Pic_A,Pic_H,Pic_U,Pic_L,Pic_S,Pic_Z,Pic_B,0);
  2284.         lschx = 8;
  2285.         lschy = 1;
  2286.     }
  2287. }
  2288.  
  2289. /*****************************  END OF DB_UTIL.C  ***************************/
  2290.